package com.gxuwz.medical.web.servlet;

import java.io.IOException;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import com.gxuwz.medical.domain.area.Area;
import com.gxuwz.medical.domain.institution.Institution;
import com.gxuwz.medical.domain.medical.Medical;
import com.gxuwz.medical.domain.medical.S201;
import com.gxuwz.medical.tools.StringUtil;

/**
 * 医疗机构管理控制处理模块
 * 
 * @author 演示
 * 
 */
public class MedicalServlet extends BaseServlet {

	@Override
	protected void doGet(HttpServletRequest request,
			HttpServletResponse response) throws ServletException, IOException {
		this.doPost(request, response);
	}

	@Override
	protected void doPost(HttpServletRequest request,
			HttpServletResponse response) throws ServletException, IOException {
		String m = request.getParameter("m");// 动作类型参数
		if ("list".equals(m)) {
			process(request, response, "/page/medical/medical_list.jsp");
		} else if ("input".equals(m)) {
			process(request, response, "/page/medical/medical_add.jsp");
		} else if ("get".equals(m)) {
			process(request, response, "/page/medical/medical_edit.jsp");
		} else if ("add".equals(m)) {
			add(request, response);
			process(request, response, "/page/medical/medical_list.jsp");
		} else if ("edit".equals(m)) {
			edit(request, response);
			process(request, response, "/page/medical/medical_list.jsp");
		} else if ("del".equals(m)) {
			del(request, response);
			process(request, response, "/page/medical/medical_list.jsp");
		} else {
			error(request, response);
		}
	}

	/**
	 * 添加机构方法
	 * 
	 * @param request
	 * @param response
	 * @throws ServletException
	 * @throws IOException
	 */
	private void add(HttpServletRequest request, HttpServletResponse response)
			throws ServletException, IOException {
		// 接收页面传递过来的参数
		String jgbm = request.getParameter("jgbm");
		String zzjgbm = request.getParameter("zzjgbm");
		String jgmc = request.getParameter("jgmc");
		String dqbm = request.getParameter("dqbm");
		String areacode = request.getParameter("areacode");
		String strlsgx = request.getParameter("lsgx");
		String strjgjb = request.getParameter("jgjb");
		String strsbddlx = request.getParameter("sbddlx");
		String strpzddlx = request.getParameter("pzddlx");
		String strssjjlx = request.getParameter("ssjjlx");
		String strwsjgdl = request.getParameter("wsjgdl");
		String strwsjgxl = request.getParameter("wsjgxl");
		String zgdw = request.getParameter("zgdw");
		String kysj = request.getParameter("kysj");// 日期
		String frdb = request.getParameter("frdb");
		String zczjnum = request.getParameter("zczj");// 数值
		double zczj = Double.parseDouble(zczjnum);

		S201 lsgx = new S201(strlsgx, "", "02");
		S201 jgjb = new S201(strjgjb, "", "06");
		S201 sbddlx = new S201(strsbddlx, "", "04");
		S201 pzddlx = new S201(strpzddlx, "", "04");
		S201 ssjjlx = new S201(strssjjlx, "", "01");
		S201 wsjgdl = new S201(strwsjgdl, "", "03");
		S201 wsjgxl = new S201(strwsjgxl, "", "0301");
		jgbm = StringUtil.trim(jgbm);
		// 调用添加方法
		try {
			Medical model = new Medical(jgbm, zzjgbm, jgmc, dqbm, areacode,
					lsgx, jgjb, sbddlx, pzddlx, ssjjlx, wsjgdl, wsjgxl, zgdw,
					kysj, frdb, zczj);
			model.add();
		} catch (Exception e) {

			e.printStackTrace();
		}

	}

	/**
	 * 自己写的修改删除
	 */

	private void edit(HttpServletRequest request, HttpServletResponse resp)
			throws ServletException, IOException {

		// 接收页面传递过来的参数
		String jgbm = request.getParameter("jgbm");
		String zzjgbm = request.getParameter("zzjgbm");
		String jgmc = request.getParameter("jgmc");
		String dqbm = request.getParameter("dqbm");
		String areacode = request.getParameter("areacode");
		String strlsgx = request.getParameter("lsgx");
		String strjgjb = request.getParameter("jgjb");
		String strsbddlx = request.getParameter("sbddlx");
		String strpzddlx = request.getParameter("pzddlx");
		String strssjjlx = request.getParameter("ssjjlx");
		String strwsjgdl = request.getParameter("wsjgdl");
		String strwsjgxl = request.getParameter("wsjgxl");
		String zgdw = request.getParameter("zgdw");
		String kysj = request.getParameter("kysj");// 日期
		String frdb = request.getParameter("frdb");
		String zczjnum = request.getParameter("zczj");// 数值
		double zczj = Double.parseDouble(zczjnum);

		S201 lsgx = new S201(strlsgx, "", "02");
		S201 jgjb = new S201(strjgjb, "", "06");
		S201 sbddlx = new S201(strsbddlx, "", "04");
		S201 pzddlx = new S201(strpzddlx, "", "04");
		S201 ssjjlx = new S201(strssjjlx, "", "01");
		S201 wsjgdl = new S201(strwsjgdl, "", "03");
		S201 wsjgxl = new S201(strwsjgxl, "", "0301");
		jgbm = StringUtil.trim(jgbm);

		try {
			Medical model = new Medical(jgbm, zzjgbm, jgmc, dqbm, areacode,
					lsgx, jgjb, sbddlx, pzddlx, ssjjlx, wsjgdl, wsjgxl, zgdw,
					kysj, frdb, zczj);
			model.editMe();
		} catch (Exception e) {
			e.printStackTrace();

		}
	}

	private void del(HttpServletRequest request, HttpServletResponse resp)
			throws ServletException, IOException {
		// 接收页面传递过来的参数
		String jgbm = request.getParameter("id");

		Medical medical = new Medical();
		try {
			medical.delMe(jgbm);
		} catch (Exception e) {
			e.printStackTrace();

		}
	}

}
